import {ApiFetch,} from "../api/apiHandler";
import {BaseUrl,} from "../constant/constant";

class MessageModel {

    constructor(type) {
        this.url = BaseUrl
        this.type = type
        this.mapper = {
            all: {
                'user': 'getsystemmsglist',
                'vip': 'getvipmsglist',
            },
            add: {
                'user': 'addsystemmsg',
                'vip': 'addvipmsg',
            },
            delete: {
                'user': 'delsystemmsg',
                'vip': 'delvipmsg',
            },
            clear: {
                'user': 'clearsystemmsg',
                'vip': 'clearvipmsg',
            },
        }
    }

    all(params) {
        let type = this.type
        let m = this.mapper.all
        let end = this.url + m[type]
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    add(params) {
        let m = this.mapper.add
        let end = this.url + m[this.type]
        let req = new ApiFetch(end)
        return req.fetch(params)
        // .then((data) => console.log(data))
    }

    delete(params, config) {
        let m = this.mapper.delete
        let end = this.url + m[this.type]
        let req = new ApiFetch(end)
        return req.fetch(params)
    }

    clear(params, config) {
        let m = this.mapper.clear
        let end = this.url + m[this.type]
        let req = new ApiFetch(end)
        return req.fetch(params)
    }
}

export default MessageModel

